/*
 * adaboost_face.h
 *
 *  Created on: 2016年3月15日
 *      Author: guyadong
 */

#ifndef FACEDETECT_CL_FILES_ADABOOST_FACE_H_
#define FACEDETECT_CL_FILES_ADABOOST_FACE_H_
#include "common_types.h"
#define MAX_LAYER_NUM 50
#define MAX_WEIGHT_NUM 6000
typedef struct _casinfo_base{
	cl_int CasNum;
	cl_int FeaNumPerLayer[MAX_LAYER_NUM];
	cl_double Weight[MAX_WEIGHT_NUM];
	cl_double LayerWeight[MAX_LAYER_NUM];
	cl_int FeatherNumPerCas;
}casinfo_base;

// used for  device not supported double
typedef struct _casinfo_base_float{
	cl_int CasNum;
	cl_int FeaNumPerLayer[MAX_LAYER_NUM];
	cl_float Weight[MAX_WEIGHT_NUM];
	cl_float LayerWeight[MAX_LAYER_NUM];
	cl_int FeatherNumPerCas;
}casinfo_base_float;

typedef struct {
	cl_int x;
	cl_int y;
	cl_int Width;

	cl_int Height;
	cl_int Up_Down;
	cl_uchar RectangleNum;
	cl_int  Valve;
	cl_float DValve;
	cl_int Sign;
	cl_int CorrectNum;
	cl_int NonfaceCorrectNum;
	cl_int unitWidth;
	cl_int unitHeight;
}feather_cl;

typedef struct _feather_short_cl{
	cl_float DValve;
	cl_short x;
	cl_short y;
	cl_short Width;
	cl_short Height;
	cl_short Up_Down;
	cl_short  Valve;
	cl_short CorrectNum;
	cl_short NonfaceCorrectNum;
	cl_short unitWidth;
	cl_short unitHeight;
	cl_char  Sign;
	cl_uchar RectangleNum;
}feather_short_cl;
typedef struct _haar_filter_const_param{
	// must first member for alignment,otherwise will be throw exception from kernel
	cl_float2 normalization_factor;
	cl_int 	win_size;
	cl_int 	sample_step;
	cl_float dvalve_square;
	cl_float inv_pixels_num;
	cl_uint detect_scale_level;
}haar_filter_const_param;
typedef struct _feather_block_base{
	cl_int start_layer,end_layer,offset;
}feather_block_base;

typedef struct _haar_filter_group_cycle_const_param{
	cl_int cas_num;
	cl_int feather_num_per_cas;
	cl_int const_size;
	cl_int sample_step;
	matrix_info_cl im_info;
	matrix_info_cl om_info;
}haar_filter_group_cycle_const_param;
typedef struct _filter2_const_param{
	cl_int 	sample_step;
}filter2_const_param;

typedef struct _cluster_filter_const_param {
	// must first member for alignment,otherwise will be throw exception from kernel
	cl_int2 img_size;
	cl_int 	win_size;
	cl_int  face_dist_size;
}cluster_filter_const_param;
typedef struct _cluster_filter_const_param1 {
	// must first member for alignment,otherwise will be throw exception from kernel
	cl_float2 normalization_factor;
	cl_int 	win_size;
	cl_int  face_dist_size;
	cl_int sample_step;
}cluster_filter_const_param1;
#define MAX_DETECTED_OBJECT_NUM 2048
#define MAX_DETECTED_OBJECT_NUM_LEVEL 4096
typedef enum _kernel_error {
	 KERNEL_OK
	,KERNEL_OUT_INDEX
	,KERNEL_OUT_LOCAL_INDEX
	,KERNEL_ZERO_OBJ_SUM
}kernel_error;
#ifdef __cplusplus
#include <string>
#define _CASE_VALUE_RETURN_STR_(v) case v:return #v;
static std::string kernel_error_msg(kernel_error err){
	switch(err){
	_CASE_VALUE_RETURN_STR_(KERNEL_OK)
	_CASE_VALUE_RETURN_STR_(KERNEL_OUT_INDEX)
	_CASE_VALUE_RETURN_STR_(KERNEL_OUT_LOCAL_INDEX)
	_CASE_VALUE_RETURN_STR_(KERNEL_ZERO_OBJ_SUM)
	default:
		return "Unknown error";
	}
}
#undef _CASE_VALUE_RETURN_STR_
#endif // __cplusplus


typedef struct  _detected_objects_buffer_norm {
	// x,y object location (normalized coordinate)
	// z, object sum
	// w, detect win size (normalized)
	// must 16-byte aligned,otherwise will be throw exception from kernel
	cl_float4 storage[MAX_DETECTED_OBJECT_NUM];
	cl_int 	detected_num;
	kernel_error status;
}detected_objects_buffer_norm;
typedef struct  _detected_objects_buffer_level {
	// x,y object location (normalized coordinate)
	// z, object sum
	// must 8-byte aligned,otherwise will be throw exception from kernel
	cl_ushort4 storage[MAX_DETECTED_OBJECT_NUM_LEVEL];
	cl_int 	detected_num;
	kernel_error status;
}detected_objects_buffer_level;
#define F1_LOCAL_SIZE 16
#define F2_LOCAL_SIZE 16
#define HAAR_LOCAL_SIZE 64
#define DENSITY_LOCAL_SIZE 64

#define MEAN_LOCAL_SIZE 64
#define VARIANCE_LOCAL_SIZE 64
#define HAAR_FILTER_LOCAL_WIDTH 8
#define HAAR_FILTER_LOCAL_HEIGHT 8
#define DENSITY_FILTER_LOCAL_SIZE 64
//106 old MAXVAR
#define VARIANCE_MAXVAR 93.6
// old MINVAR
#define VARIANCE_MINVAR 13.1

#ifdef __cplusplus
inline bool operator==(const feather_cl&f1,const feather_cl&f2){
	return	   f1.x==f2.x
			&& f1.y==f2.y
			&& f1.Width==f2.Width
			&& f1.Height==f2.Height
			&& f1.Up_Down==f2.Up_Down
			&& f1.RectangleNum==f2.RectangleNum
			&& f1.Valve==f2.Valve
			&& f1.DValve==f2.DValve
			&& f1.Sign==f2.Sign
			&& f1.CorrectNum==f2.CorrectNum
			&& f1.NonfaceCorrectNum==f2.NonfaceCorrectNum
			&& f1.unitWidth==f2.unitWidth
			&& f1.unitHeight==f2.unitHeight
			;
}
inline bool operator!=(const feather_cl&f1,const feather_cl&f2){
	return !(f1==f2);
}
#endif
#endif /* FACEDETECT_CL_FILES_ADABOOST_FACE_H_ */
